package com.gdit.zax.servletjsp;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.gdit.zax.Constant;
import com.gdit.zax.dao.CommentDao;
import com.gdit.zax.dao.UserDao;
import com.gdit.zax.entitys.CommentAll;
import com.gdit.zax.entitys.UserInfo;
import com.gdit.zax.factory.DAOFactory;
import com.gdit.zax.utils.DBUtil;
import com.gdit.zax.utils.LogUtil;
import com.gdit.zax.utils.Repost;
import com.gdit.zax.utils.TextUtil;
import com.gdit.zax.utils.webUtil;

public class AdmComment extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doPost(request, response);
	}
	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		//变量准备
		String token = webUtil.getCookie(request, "LoginCookie");
		int onepagecount = TextUtil.String2int(request.getParameter("onepagecount"), 10);
		int page = TextUtil.String2int(request.getParameter("page"), 1);
		
		
		//数据库，权限检测
		Connection conn = DBUtil.getConnection();
		if (conn==null) {
			Repost.dberror(request,response);
			return;
		}
		
		DAOFactory dao = DAOFactory.init(conn,request,response);
		UserDao udao = dao.getUserDao();
		UserInfo uinfo = udao.getInfo(Constant.LOGINTYPE_WEB, token);
		if (uinfo==null) {
			Repost.nologin(response);
			return;
		}
		if (uinfo.getUlevel() < Constant.ULEVEL_teacher) {
			Repost.message("你还没有权限!", request, response);
		}
		
		//开始
		CommentDao cdao = dao.getCommentDao();
		ArrayList<CommentAll> list = cdao.listMySendComment(uinfo.getId(), page, onepagecount);
		request.setAttribute("data", list);
		Repost.success("admcomment.jsp", request, response);
		
		
		
	}

}
